package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class Retuenbook implements Operate{
    @Override
    public void work(BookList books) {
        System.out.println("归还书籍....");
        System.out.print("请输入你要归还的图书：-->");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();

        int count = books.getUsedbooks();
        for (int i = 0; i < count; i++) {
            if (books.getbook(i).getName().equals(name)) {
                if (books.getbook(i).isIsborrow() == true) {
                    books.getbook(i).setIsborrow(false);
                    System.out.println("归还成功---欢迎再次借阅");
                    System.out.println(books.getbook(i));
                    System.out.println();
                    return;
                }else{
                    System.out.println("这本书没有被借出，不需要归还---");
                    System.out.println();
                    return ;
                }
            }
        }
        System.out.println("查找不到你要归还的书籍，你可能是在其他图书馆借阅的书籍---");
        System.out.println();
    }
}
